package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.ViewAppointment;
import com.atguigu.lease.web.app.mapper.ApartmentInfoMapper;
import com.atguigu.lease.web.app.mapper.ViewAppointmentMapper;
import com.atguigu.lease.web.app.service.ViewAppointmentService;
import com.atguigu.lease.web.app.vo.apartment.ApartmentItemVo;
import com.atguigu.lease.web.app.vo.appointment.AppointmentDetailVo;
import com.atguigu.lease.web.app.vo.appointment.AppointmentItemVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liubo
 * @description 针对表【view_appointment(预约看房信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
        implements ViewAppointmentService {

    @Autowired
    private ViewAppointmentMapper viewAppointmentMapper;

    @Autowired
    private ApartmentInfoMapper apartmentInfoMapper;


    @Override
    public List<AppointmentItemVo> customByUserId(Integer userId) {
        List<AppointmentItemVo> appointmentItemVoList = viewAppointmentMapper.customSelectByUserId(userId);
        return appointmentItemVoList;
    }

    @Override
    public AppointmentDetailVo customGetById(Long id) {
        LambdaQueryWrapper<ViewAppointment> lambdaQueryWrapper
                = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ViewAppointment::getId,id);
        ViewAppointment viewAppointment = getById(id);
        Long apartmentId = viewAppointment.getApartmentId();
        ApartmentItemVo apartmentItemVo = apartmentInfoMapper.customSelectById(apartmentId);
        AppointmentDetailVo appointmentDetailVo = new AppointmentDetailVo();

        appointmentDetailVo.setApartmentItemVo(apartmentItemVo);
        appointmentDetailVo.setId(viewAppointment.getId());
        appointmentDetailVo.setUserId(viewAppointment.getUserId());
        appointmentDetailVo.setName(viewAppointment.getName());
        appointmentDetailVo.setPhone(viewAppointment.getPhone());
        appointmentDetailVo.setApartmentId(viewAppointment.getApartmentId());
        appointmentDetailVo.setAppointmentTime(viewAppointment.getAppointmentTime());
        appointmentDetailVo.setAdditionalInfo(viewAppointment.getAdditionalInfo());
        appointmentDetailVo.setAppointmentStatus(viewAppointment.getAppointmentStatus());


        return appointmentDetailVo;
    }
}




